package com.gxa.user.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.user.dto.EmailParam;
import com.gxa.user.dto.Keywords;
import com.gxa.user.dto.MyParam;
import dto.ResultDTO;
import com.gxa.user.service.MemberService;
import entity.City;
import entity.Member;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import util.Response;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Member)表控制层
 *
 * @author makejava
 * @since 2021-05-10 19:01:14
 */
@RestController
@RequestMapping("user")
@Api(tags = "员工模块")
public class MemberController {
    /**
     * 服务对象
     */
    @Resource
    private MemberService memberService;

//    员工管理--------------------------------------------
    /**
     * 查询所有
     * @param param
     * @return
     */
    @PostMapping("list")
    @ApiOperation(value = "查询所有员工")
//    @OperateLogConfig
    public ResultDTO memberList(@RequestBody MyParam param){
        PageInfo info = memberService.findAll(param);
        return Response.success(200,"查询成功",info);
    }

    /**
     * 新增员工
     */
    @PostMapping("add")
    @ApiOperation(value = "新增员工")
    public ResultDTO addUser(@RequestBody @Validated Member member){
        return memberService.insertUser(member);
    }

    /**
     * 删除用户
     * @return
     */
    @PostMapping("delete/user")
    @ApiImplicitParam(name = "memberId", value = "用户Id",required = true)
    @ApiOperation(value = "删除用户")
    public ResultDTO delete(@RequestBody Member member){
        return memberService.delete(member.getMemberId());
    }

    /**
     * 禁用用户
     * @return
     */
    @PostMapping("disable/user")
    @ApiOperation(value = "禁用用户")
    @ApiImplicitParam(name = "memberId", value = "用户id",required = true)
    public ResultDTO disable(@RequestBody Member member){
        return memberService.disable(member.getMemberId());
    }

    /**
     * 启用用户
     * @return
     */
    @PostMapping("able/user")
    @ApiImplicitParam(name = "memberId", value = "用户id",required = true)
    @ApiOperation(value = "启用用户")
    public ResultDTO able(@RequestBody Member member){
        return memberService.able(member.getMemberId());
    }

    /**
     * 根据关键词查询
     */
    @PostMapping("find/keywords")
    @ApiImplicitParam(name = "keywords", value = "关键字")
    @ApiOperation(value = "前端--根据关键字查询")
    public ResultDTO able(@RequestBody Keywords keywords){
        return memberService.queryByKeywords(keywords);
    }


//cx--------------------------------------------------------------
    /**
     * 根据id查询用户是否存在--------cx+hh
     * @return
     */
    @PostMapping("get/byMemberId")
    @ApiOperation(value = "根据id查询用户是否存在--cx+hh")
    public ResultDTO findByMemberId(@RequestBody Integer memberId){
        return memberService.query(memberId);
    }

    /**
     * 根据传入对象，判断传入信息是否存在--------cx
     * @return
     */
    @PostMapping("get/byMember")
    @ApiOperation(value = "根据传入对象，判断传入信息是否存在--cx")
    public ResultDTO queryMember(@RequestBody Member member){
        System.out.println(member);
        return memberService.queryMember(member);
    }


//tt------------------------------------------------------------------------------------
    /**
     * 根据用户id查询所有信息，包括角色等
     */
    @PostMapping("find/all/byMemberId")
    @ApiImplicitParam(name = "memberId", value = "用户id")
    @ApiOperation(value = "根据用户id查询所有信息，包括角色等----tt")
    public ResultDTO findAllById(@RequestParam Integer memberId){
        return memberService.findAllByTt(memberId);
    }


    /**
     * 查询管理员邮箱
     */
    @PostMapping("find/email")
    @ApiOperation(value = "查询管理员邮箱----tt")
    public ResultDTO selectEmail(){
        return memberService.selectEmail();
    }

//hh---------------------------------------------------------------
    /**
     * 根据部门id和角色id查询
     */
    @PostMapping("find/deptId/roleId")
    @ApiOperation(value = "根据部门id和角色id查询--hh")
    public ResultDTO findByDeptIdAndRoleId(@RequestParam Integer deptId,@RequestParam Integer roleId){
        return memberService.findByDeptIdAndRoleId(deptId,roleId);
    }


    /**
     * 查询总经理
     */
    @PostMapping("find/boss")
    @ApiOperation(value = "查询总经理--hh")
    public ResultDTO findBoss(){
        return memberService.findBoss();
    }


//    个人信息----------------------------------------
    /**
     * 根据城市Id查城市
     */
    @PostMapping("find/city")
    @ApiOperation(value = "根据城市Id查城市")
    public ResultDTO findCity(@RequestBody City city){
        return memberService.findByCityId(city.getCityId());
    }


    /**
     * 查询城市和城市Id
     */
    @PostMapping("find/cityAndCityId")
    @ApiOperation(value = "查询城市和城市Id")
    public ResultDTO findCityAndCityId(){
        return memberService.findCityAndCityId();
    }

    /**
     * 发送邮件
     */
    @PostMapping("send/email")
    @ApiOperation(value = "发送邮件")
    public ResultDTO sendEmail(@RequestBody Member member){
        return memberService.sendEmail(member);
    }

    /**
     * 发送邮件改密码
     */
    @PostMapping("update/pwdByEmail")
    @ApiOperation(value = "发送邮件改密码")
    public ResultDTO updatePwdByEmail(@RequestBody EmailParam emailParam){
        return memberService.updatePwd(emailParam.getMemberId(),emailParam.getNewPwd(),emailParam.getCode());
    }

    /**
     * 通过原密码改密码
     */
    @PostMapping("update/pwdBypwd")
    @ApiOperation(value = "通过原密码改密码")
    public ResultDTO updatePwd(@RequestBody EmailParam emailParam){
        return memberService.updatePassword(emailParam.getMemberId(),emailParam.getMemberPwd(),emailParam.getNewPwd());
    }

    /**
     * 修改员工所有信息
     */
    @PostMapping("update/userAll")
    @ApiOperation(value = "修改员工所有信息")
    public ResultDTO updateAll(@RequestBody @Validated Member member){
        return memberService.updateAll(member);
    }

    /**
     * 设置用户为常用旅客
     */
    @PostMapping("update/isUsual")
    @ApiOperation(value = "设置用户为常用旅客")
    public ResultDTO updateisUsual(@RequestBody Member member){
        return memberService.updateIsUsual(member.getMemberId(),member.getIsUsual());
    }
//    ff-----------------------------------------------------------------
    /**
     * 查询所有，不带分页
     */
    @PostMapping("find/allNoPage")
    @ApiOperation(value = "查询所有，不带分页")
    public ResultDTO findAllNoPage(){
        return memberService.findAllNoPage();
    }


    /**
     * 根据用户id查询所有--前端
     */
    @PostMapping("select/all/byMemberId")
    @ApiImplicitParam(name = "memberId", value = "用户id")
    @ApiOperation(value = "根据用户id查询所有信息")
    public ResultDTO selectAllById(@RequestBody Member member){
        return memberService.findAllById(member.getMemberId());
    }


    /**
     * 上传图片
     */
    @PostMapping("upload/img")
    @ApiOperation(value = "上传图片")
    public ResultDTO uploadImg(Integer memberId,MultipartFile file){
        return memberService.updateImg(memberId,file);
    }
}
